package com.sync.syncmasterdata;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sync.syncmasterdata.customer.pojo.MayCurPartner;
import com.sync.syncmasterdata.customer.pojo.U8Customer;
import com.sync.syncmasterdata.customer.service.http.HttpAPIServiceForCrmSync;
import com.sync.syncmasterdata.customer.service.impl.SyncServiceImpl;
import com.sync.syncmasterdata.product.controller.ProductController;
import com.sync.syncmasterdata.product.pojo.oa.InventoryForOA;
import com.sync.syncmasterdata.product.service.SyncInventoryService;
import com.sync.syncmasterdata.vendor.pojo.U8Vendor;
import com.sync.syncmasterdata.vendor.service.SyncVendorServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SpringBootTest
@Slf4j
class SyncMasterDataApplicationTests2 {

    @Autowired
    private ProductController con;

    @Autowired
    private SyncInventoryService syncInventoryService;

    @Autowired
    private ObjectMapper objectMapper;

    @Autowired
    private HttpAPIServiceForCrmSync httpAPIServiceForCrmSync;


    @Test
    void contextLoads() {
    }

    //产品测试
//    @Test
//    public void test1() {
//        InventoryForOA oa = new InventoryForOA();
//        oa.setChanpinlx("SJ04");
//        oa.setCunhuobm("SJ04362");
//        oa.setChanpinmc("SJ04362测试推送产品");
//        oa.setHuohao("产品货号");
//        oa.setGuigexh("产品规格型号");
//        oa.setZhujildw("001");
//        oa.setPinpaiwb("品牌字段");
//        oa.setShengchanqy("N3101123");
//        oa.setShengchanqywb("生产企业文本");
//        oa.setGuochanjk(1);
//        oa.setShifouylqx(0);
//        oa.setYewulx("业务类型");
//        oa.setChanpinx("产品线");
//        oa.setChanpinz("产品组");
//        oa.setXiangmumcwb("项目名称");
//        Map<String,Object> map=con.productSourceOa(oa);
//        System.out.println("返回值:"+map.toString());
//    }

    /**
     * 测试获取最后一个编码
     */
    @Test
    public void test2() {
        List<String> lists = new ArrayList<>();
        lists.add("YQ02");
        for (String sort : lists) {
            String s=syncInventoryService.getLastCode(sort);
            System.out.println("最后一个编码:"+String.format("%s",s));
        }
    }

    @Test
    public void getLastCode(){
        List<String> list = new ArrayList<>();
        list.add("020");
        list.add("22");
        list.add("0100");
        //转 int
        List<Integer> listInt = new ArrayList<>();
        for (String s : list) {
            listInt.add(stringToInt(s));
        }
        listInt.sort(((o1, o2) -> -1*o1.compareTo(o2)));
        System.out.println(listInt.toString());
    }
    private int stringToInt(String s) {
        try {
            return Integer.valueOf(s);
        } catch (Exception e) {
            return 0;
        }
    }



    @Test
    public void getwfinfotest() {
        String requestid="383135";
        List<InventoryForOA> oas = syncInventoryService.getWorkflowInfo(requestid);
        try {
            System.out.println("查询出的对象组：" + objectMapper.writeValueAsString(oas));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

    }

    @Test
    public void controllertest() {
        Map<String, Object> map = new HashMap<>();
        map.put("requestid","383186");
        con.productSourceOaByRequestid(map);
    }

    @Test
    public void controllerTest3() {
        String url="http://172.16.0.190:5555/crm/api/data/v8.2/accounts?$top=1&$select=name,new_erp_num,new_oa_id";
        try {
            log.info("-------------");
            String ret=httpAPIServiceForCrmSync.doGetCrm(url);
            log.info("-------------{}",ret);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
